﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace EtalkClient
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(AppThreadException);
            if (CheckProcesses())
            {
                Application.Run(new ClientMain());
            }
        }
        private static void AppThreadException(object source, System.Threading.ThreadExceptionEventArgs e)
        {
            string errorMsg = string.Format("未处理异常: \n{0}\n", e.Exception.Message);
            errorMsg += Environment.NewLine;

            DialogResult result = MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);

            //如果点击“中止”则退出程序
            if (result == DialogResult.Abort)
            {
                Application.Exit();
            }
        }
        private static bool CheckProcesses()
        {
            string strProcessName;
            strProcessName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
            if (System.Diagnostics.Process.GetProcessesByName(strProcessName).Length > 1)
            {
                MessageBox.Show("对不起，本地已经有系统正在运行，请先关闭！\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}